<template>
  <BaseContainer>
    <template #title>
      <table-toolbar>
        <template #bar-left>
          <div @click="handleBack" class="cursor-pointer">
            <arrow-left-outlined class="inline-block leading-0 ft-14 mr-2" />
            <p class="inline-block mb-0 font-bold ft-16">
              {{ `编号：${currentPriceSheet?.id ?? ''}` }}
            </p>
          </div>
        </template>
        <a-space :size="0" class="mr-5" v-if="btnVisible.showOrderSpace">
          <a-button
            type="primary"
            v-if="!orderDisabled"
            :disabled="orderLoading || tepizhuangstu"
            @click="handleShowOrderDialog"
            >提单</a-button
          >
        </a-space>
      </table-toolbar>
    </template>
    <div class="main flex justify-between">
      <a-descriptions size="small" :column="2" class="main__descriptions">
        <a-descriptions-item label="平台">{{ currentPriceSheet.platformNames || '--' }}</a-descriptions-item>
        <a-descriptions-item label="套餐" v-if="currentPriceSheet.comboName">
          <a-tooltip placement="topLeft">
            <template #title>
              {{ currentPriceSheet.comboName }}
            </template>
            <span class="ell-1">{{ currentPriceSheet.comboName }}</span>
          </a-tooltip>
        </a-descriptions-item>
        <a-descriptions-item label="投放区域" v-if="BW || BWYXB || BWSD || BWSDYXB">
          <area-popover ellipsis :areas="currentPriceSheet.areas" :product-id="currentPriceSheet.productId" />
        </a-descriptions-item>
        <a-descriptions-item
          v-if="currentPriceSheet.productId != ProductEnum.BWSD && currentPriceSheet.productId != ProductEnum.BWSDYXB"
          label="用户所在地"
          >{{ currentPriceSheet.userArea }}</a-descriptions-item
        >
        <a-descriptions-item label="投放时长">{{ currentPriceSheet.comboPriceName }}</a-descriptions-item>
        <a-descriptions-item label="类型">{{ TypeKeyMap[currentPriceSheet.type] }}</a-descriptions-item>
        <a-descriptions-item label="销售人员">{{ currentPriceSheet.sellerName }}</a-descriptions-item>
        <a-descriptions-item label="代理商">{{ currentPriceSheet.proxyName }}</a-descriptions-item>
        <a-descriptions-item label="查价日期">{{ currentPriceSheet.createTime }}</a-descriptions-item>
        <a-descriptions-item label="投放时间段" v-if="BW || BWYXB">{{
          currentPriceSheet.onLinePeriod
        }}</a-descriptions-item>
        <a-descriptions-item label="投放时间段" v-else>7*24小时</a-descriptions-item>
        <a-descriptions-item label="套餐价格" v-if="CiBao || CBYXB || BWSD || BWSDYXB">{{
          currentPriceSheet.comboPrice
        }}</a-descriptions-item>
        <a-descriptions-item
          label="套餐价格"
          v-else-if="currentPriceSheet.status === StatusEnum.PENDING && currentPriceSheet.originalIndustryCode"
          ><a @click.prevent="handlePreviewPrice"> 点击查看套餐价格</a>
        </a-descriptions-item>
        <a-descriptions-item label="黄展转移" v-if="HJBW">{{
          currentPriceSheet.hzTransferCode === IsFromHjzwEnum.Yes ? '是' : '否'
        }}</a-descriptions-item>
        <a-descriptions-item label="转移备注" v-if="HJBW && currentPriceSheet.hzTransferCode === IsFromHjzwEnum.Yes">
          {{ currentPriceSheet.hzNotes || '--' }}</a-descriptions-item
        >
      </a-descriptions>
      <div class="main__extra">
        <div class="biaotannsidx" v-if="currentPriceSheet.tpCode == 1 && currentPriceSheet.isCancel == 1">
          <a-radio @click="tepidianji" v-model:checked="checked"></a-radio>
          已仔细阅读并同意《特批订单展现预期》
        </div>
        <div class="statistic flex justify-end">
          <a-statistic
            title="报价"
            v-if="BW || BWYXB"
            :value="currentPriceSheet.marketPrice || currentPriceSheet.assessmentPrice || '--'"
            class="statistic__item mr-5"
          />

          <a-statistic
            title="市场价"
            v-else-if="mainStore.userInfo?.proxy_id !== 1377 && mainStore.userInfo?.proxy_id !== 1407"
            :value="currentPriceSheet.comboPrice"
            class="statistic__item mr-5"
          />
          <a-statistic title="当前状态" :value="StatusKeyMap[currentPriceSheet.status]" class="statistic__item" />
        </div>
      </div>
    </div>
    <Divider />
    <table-toolbar title="审核反馈">
      <a-button
        type="primary"
        @click="handleChangeAudit"
        :disabled="auditResultDisabled"
        v-if="btnVisible.showAuditBtn"
      >
        <plus-outlined />
        添加审核结果
      </a-button>
    </table-toolbar>
    <a-table
      class="mb-5"
      row-key="id"
      :loading="loading"
      :pagination="false"
      :columns="columns"
      :data-source="auditResult"
    >
      <template #bodyCell="{ record, column }">
        <template v-if="column.key === 'approveTime'">
          {{ formatDate(record.approveTime) }}
        </template>
        <template v-if="column.key === 'approved'">
          {{ formatDate(record.approveTime) }}
        </template>
      </template>
    </a-table>
    <SelectedTable
      ref="SelectedTableRef"
      show-heat-rate
      :scroll="{ y: null }"
      :bordered="false"
      :show-operate="false"
      :category="currentPriceSheet.productId"
      :selected-table-data="priceAskWords"
      :msiusidppoi="1"
      :platform-names="currentPriceSheet.platformNames"
    >
      <template #toolbar="{ columns }">
        <table-toolbar title="已选关键词">
          <export-excel-group :col="columns" :data="priceAskWords" @on-export="handleExportExcel" />
        </table-toolbar>
      </template>
    </SelectedTable>
    <AuditResultUpdater
      v-if="dialog.show"
      v-model:show="dialog.show"
      v-model:data="formFields"
      :loading="industryPriceLoading"
      :submitting="submitting"
      :industry-list="industryList"
      :prompt="currentPriceSheet.prompt"
      :getRenewDasius="getRenewDas"
      :proxyIds="currentPriceSheet.proxyId"
      @on-industry-change="handleIndustryChange"
      @on-submit="submitAuditResult"
      @on-price-input="handlePriceInput"
      @on-price-inputs="handlePriceInputs"
      @on-tp-type-change="handleTpTypeChange"
    />
    <SubmitOrder
      v-model:show="orderDialog.show"
      v-model:data="orderFields"
      :customer-loading="customerLoading"
      :customer-list="customerList"
      :loading="oldCustomerLoading"
      :disabled="disabledIfOldOrder"
      :submitting="orderLoading"
      @on-submit="handleOrderSubmit"
      @on-search="handleCustomerSearch"
    />
    <a-modal v-model:visible="previewDialog.show" :width="1000" title="套餐价格" @ok="previewDialog.show = false">
      <BwPriceTable
        :loading="priceLoading"
        :price-table="priceUtils.baiduTable.value"
        :xy="priceUtils.baiduCoordinates.value"
      />
      <div v-if="hasCreativePic" class="mt-5">
        <BwCreativeCard :show-only="true" :disabled="false" :select="hasCreativePic" :price-utils="priceUtils" />
      </div>
      <div style="margin-top: 10px; text-align: end">
        <span>总价：</span
        ><span style="color: red">{{
          currentPriceSheet?.marketPrice || currentPriceSheet?.assessmentPrice || '--'
        }}</span>
      </div>
    </a-modal>

    <div>
      <!-- <a-button type="primary" @click="showModal">Open Modal</a-button> -->
      <a-modal v-model:visible="visibletepi" title="已仔细阅读并同意《特批订单展现预期》" @ok="handleOktepi">
        <div class="tepititlecas">
          {{ tepititle }}
        </div>
        <div class="tepicontentca">
          {{ tepicontent }}
        </div>
      </a-modal>
    </div>
  </BaseContainer>
</template>

<script lang="ts" setup>
import { usePriceSheetStore } from '@/store/usePriceSheetStore'
import { computed, onBeforeMount, onMounted, reactive, ref, unref } from 'vue'
import SelectedTable from '@/views/price-sheet/components/SelectedTable.vue'
import getAuditResult, { type AuditResult } from '@/services/price-sheet/getAuditResult'
import { formatDate } from '@/utils'
import getCustomerList from '@/services/price-sheet/getCustomerList'
import { message, Modal } from 'ant-design-vue'
import { type OrderFields, showOrderBtn } from '@/views/price-sheet/interface'
import updateAuditResult from '@/services/price-sheet/updateAuditResult'
import type { AuditResultType } from '@/services/price-sheet/updateAuditResult'
import AuditResultUpdater from '@/views/price-sheet/components/AuditResultUpdater.vue'
import { useRouter } from 'vue-router'
import { storeToRefs } from 'pinia'
import submitOrder from '@/services/order/submitOrder'
import SubmitOrder from '@/views/price-sheet/components/SubmitOrder.vue'
import { useMainStore } from '@/store/useMainStore'
import TableToolbar from '@/components/table-toolbar/index.vue'
import getIndustryList from '@/services/order/getIndustryList'
import { ArrowLeftOutlined, PlusOutlined } from '@ant-design/icons-vue'
import getPriceAskWords from '@/services/price-sheet/getPriceAskWords'
import BaseContainer from '@/components/base-container/index.vue'
import Divider from '@/components/divider/index.vue'
import getAssessmentPrice from '@/services/price-sheet/getAssessmentPrice'
import AreaPopover from '@/components/area-popover/index.vue'
import { useCategory } from '@/hooks/useCategotry'
import { cloneDeep, isNil, omit } from 'lodash-es'
import BwPriceTable from '@/views/price-sheet/components/BwPriceTable.vue'
import getAssessmentPriceAskWord from '@/services/price-sheet/getAssessmentPriceAskWord'
import { ApproveStatusEnum, StatusEnum } from '@/core/enums/status'
import { ApproveStatusKeyMap, StatusKeyMap } from '@/core/mapper/status'
import { PermissionEnum } from '@/core/enums/auth'
import { PlatformEnum } from '@/core/enums/platform'
import { ProductKeyMap } from '@/core/mapper/platform'
import { TypeKeyMap } from '@/core/mapper/type'
import ExportExcelGroup from '@/components/export-excel-group/index.vue'
import dayjs from 'dayjs'
import getOldOrderCustomer from '@/services/order/getOldOrderCustomer'
import getRenewDetail from '@/services/account-management/getRenewDetail'
import { CreativePictureEnum, TypeEnum } from '@/core/enums/type'
import { usePriceTable } from '@/views/price-sheet/hooks/usePriceTable'
import { usePriceCoordinates } from '@/views/price-sheet/hooks/usePriceCoordinates'
import BwCreativeCard from '@/views/price-sheet/components/BwCreativeCard.vue'
import { add, div, mul, toFixed } from '@/utils/math'
import { IsFromHjzwEnum, IsTPEnum } from '@/core/enums/type'
import { ProductEnum } from '@/core/enums/platform'
import getSpecialApproveText from '@/services/account-management/getSpecialApproveText'

const checked = ref(false)
const router = useRouter()
const tonguobashuj = ref(true)
const mainStore = useMainStore()
const priceSheetStore = usePriceSheetStore()
const { currentPriceSheet, detailPagePermission } = storeToRefs(priceSheetStore)
const { BW, CiBao, HJBW, BWYXB, CBYXB, BWSD, BWSDYXB } = useCategory(currentPriceSheet.value.productId)
const SelectedTableRef = ref<InstanceType<typeof SelectedTable>>()
const auditResultDisabled = ref(false)
const orderDisabled = ref(false)
const [, getSpecialApproveTextFn] = getSpecialApproveText()
const hasCreativePic = ref(currentPriceSheet.value.hasCreatePic === CreativePictureEnum.yes)
const dialog = reactive({
  show: false
})
const orderDialog = reactive({
  show: false
})
const confirm = reactive({
  show: false
})
const previewDialog = reactive({
  show: false
})
const visibletepi = ref(false)
const [auditResult, fetchAuditResult, loading] = getAuditResult()
const [customerList, fetchCustomerList, customerLoading] = getCustomerList()
const [priceAskWords, fetchPriceAskWords] = getPriceAskWords()
const [, postAuditResult, submitting] = updateAuditResult()
const [, fetchOrder, orderLoading] = submitOrder()
const [industryList, fetchIndustryList] = getIndustryList()
const [, fetchAssessmentPrice, industryPriceLoading] = getAssessmentPrice()
const [baiduPrice, fetchAssessmentPriceAskWord, priceLoading] = getAssessmentPriceAskWord()
const [, fetchOldOrderCustomer, oldCustomerLoading] = getOldOrderCustomer()
const [, getRenewDetailFn, oldCustomerLoadings] = getRenewDetail()

const defaultFormFields = () => ({
  userId: currentPriceSheet.value.userId,
  priceAskId: currentPriceSheet.value.id,
  approverId: currentPriceSheet.value.userId,
  approverName: mainStore.userInfo?.full_name ?? '',
  approveStatus: undefined,
  approveInfo: '',
  industryId: undefined,
  sellerId: currentPriceSheet.value.sellerId,
  // industryCode 可能会返回0，在不合法返回值的情况下，存在绕开校验规则的情况出现，所以使用<或>将0改为undefined
  industryCode: currentPriceSheet.value.industryCode || undefined,
  assessmentPrice: currentPriceSheet.value.assessmentPrice || undefined,
  marketPrice: currentPriceSheet.value.marketPrice || undefined,
  comboPrice: currentPriceSheet.value.comboPrice,
  productId: currentPriceSheet.value.productId,
  originalAssessmentPrice: currentPriceSheet.value.originalAssessmentPrice,
  tpCode: IsTPEnum.No,

  tpType: undefined,
  tpNotes: undefined,
  tpAmount: undefined
})
const defaultOrderFields = () => ({
  assessmentPrice: currentPriceSheet.value.assessmentPrice,
  customerId: undefined
})
//
const formFields = ref<Partial<AuditResult>>(defaultFormFields())
// console.log(formFields.value, '你劈我瓜是吧')

const orderFields = ref<Partial<OrderFields>>(defaultOrderFields())
function makeMarketPrice(price?: number | string | null) {
  const premiumRatio = currentPriceSheet.value.premiumRatio || 1
  price = Number(price) || 0
  if (hasCreativePic.value && price > 0) {
    const premiumPrice = mul(premiumRatio, div(1 + 0.2, price))
    return Number(toFixed(0, add(mul(0.2, premiumPrice), premiumPrice)))
  } else if (price > 0) {
    return Number(toFixed(0, mul(premiumRatio, price)))
  } else {
    return 0
  }
}
const selectedCustomer = computed(() => {
  return customerList.value.find((customer) => customer.id === orderFields.value.customerId)
})
// 如果是老订单续费，那么禁止用户选择
const disabledIfOldOrder = computed(() => {
  return !!currentPriceSheet.value.oldOrderId
})
const assessmentPrices = computed(() => {
  return baiduPrice.value
})
const premiumRatio = computed(() => {
  return currentPriceSheet.value.premiumRatio!
})
const coordinatesHook = usePriceCoordinates()
const priceUtils = usePriceTable(coordinatesHook, assessmentPrices, premiumRatio)
const getRenewDas = ref('')
const getRenewDetailFnitem = async () => {
  let [err, res] = await getRenewDetailFn({ id: currentPriceSheet.value.id })
  // console.log(res, '八嘎之时')
  if (res.data.code == 0) {
    getRenewDas.value = res.data.data
  }
}
const itsidjs = ref([])
const handleTpTypeChange = (way) => {
  console.log('接收到的 way 值：', way)
  itsidjs.value = way
  // 在这里处理接收到的 way 值
}
const tepicontent = ref('')
const tepititle = ref('')
const tepidianji = async () => {
  let [err, res] = await getSpecialApproveTextFn({ priceAskId: currentPriceSheet.value.id })
  console.log(res, '特批')
  if (res.data.code == 0) {
    tepicontent.value = res.data.data.content
    tepititle.value = res.data.data.title
  }
  visibletepi.value = true
}
const tepizhuangstu = ref(false)
// 点击关闭特批
const handleOktepi = async () => {
  console.log('确定点击了特批')
  tepizhuangstu.value = false
  visibletepi.value = false
}
const columns = [
  {
    title: '审核结果',
    dataIndex: 'approveStatus',
    key: 'approveStatus',
    width: '200px',
    customRender: ({ text }: { text: ApproveStatusEnum }) => {
      return ApproveStatusKeyMap[text]
    }
  },
  {
    title: '行业',
    dataIndex: 'industryName',
    key: 'industryName',
    width: '200px',
    customRender: ({ text }: { text: string }) => {
      if (!text) {
        return '--'
      }
      return text
    }
  },
  {
    title: '审核意见',
    dataIndex: 'approveInfo',
    key: 'approveInfo',
    width: '200px',
    customRender: ({ text }: { text: string }) => {
      if (!text) {
        return '--'
      }
      return text
    }
  },
  {
    title: '审核人',
    dataIndex: 'approverName',
    key: 'approverName',
    width: '200px'
  },
  {
    title: '审核日期',
    dataIndex: 'approveTime',
    key: 'approveTime',
    width: '200px'
  }
]

const btnVisible = {
  showAuditBtn: detailPagePermission.value === PermissionEnum.AUDIT,
  showOrderSpace: showOrderBtn(currentPriceSheet.value) && detailPagePermission.value === PermissionEnum.ORDER
}

function handleCustomerSearch(customerName: string) {
  return fetchCustomerList({
    customerName,
    sellerId: currentPriceSheet.value.sellerId!
  })
}

async function submitAuditResult() {
  // 检查 tpAmount 是否为空，并且 itsidjs.value 中是否包含 "扣业绩"
  console.log(formFields.value.tpCode, '这不太对把')
  // ||
  if (formFields.value.tpCode == undefined || formFields.value.tpCode == null || formFields.value.tpCode == false) {
    message.error('请先选择是否特批')
    return
  }

  if (formFields.value.tpCode == 1) {
    if (itsidjs.value.some((item) => item == '扣业绩')) {
      // 如果包含 "扣业绩"，直接返回，不再执行后续逻辑
      if (
        formFields.value.tpAmount === undefined ||
        formFields.value.tpAmount === '' ||
        formFields.value.tpAmount === null
      ) {
        message.error('优惠金额必填')
        return
      }
    }
    if (formFields.value.tpType.some((item) => item == 61)) {
      if (
        formFields.value.tpNotes === undefined ||
        formFields.value.tpNotes === '' ||
        formFields.value.tpNotes === null
      ) {
        message.error('备注必填')
        return
      }
    }
  }

  // console.log(formFields.value, '具体的值是这里吗', formFields.value)
  Modal.confirm({
    title: '提示',
    content: '确定要提交审核结果吗？',
    async onOk() {
      // const [err, res] = await postAuditResult(formFields.value as Required<AuditResult>)
      console.log(formFields.value, '具体的值是这里吗', formFields.value)

      const [err, res] = await postAuditResult({
        ...omit(formFields.value, 'tpType'),
        ...(formFields.value.tpType ? { specialApproveIds: String(formFields.value.tpType) } : {})
      })
      console.log(res, '接口之后', err)
      if (!err) {
        message.success(res.data.msg || '提交成功！')
        dialog.show = false
        priceSheetStore.setCurrentPriceSheet(res.data.data)

        await fetchAuditResult({
          priceAskId: currentPriceSheet.value.id!
        })
      } else {
        // Display the error message from the API response
        message.error(err.message || '提交失败')
      }
    }
  })
}

// 选择行业后需要查询一次订单对应该行业的价格
async function handleIndustryChange() {
  // 如果删除选中，那么对行业估价置空
  if (isNil(formFields.value.industryCode)) {
    formFields.value.assessmentPrice = undefined
    formFields.value.industryId = undefined
    return
  }

  const [err, res] = await fetchAssessmentPrice({
    subjectCode: formFields.value.industryCode!,
    priceAskId: formFields.value.priceAskId!
  })

  if (!err) {
    formFields.value.assessmentPrice = res.data.data?.assessmentPrice
    formFields.value.marketPrice = res.data.data?.marketPrice

    const originPrice = currentPriceSheet.value.originalAssessmentPrice

    // 原价为空或者等于0，则在选择行业后将估价作为原价
    // 只有这种情况会修改原价
    if (Number(originPrice) === 0 || isNil(originPrice)) {
      formFields.value.originalAssessmentPrice = res.data.data?.assessmentPrice
    }
  } else {
    // 行业审核失败就清除选中的行业和行业估算价格
    formFields.value.assessmentPrice = undefined
    formFields.value.industryCode = undefined
    formFields.value.industryId = undefined
  }
}

// 提单的时候如果是双端，那么需要把词从两个词(pc+mobile)合并为一个词(Platform)
function mergeOrderWordsIfPlatform() {
  if (currentPriceSheet.value.clientType === PlatformEnum.Platform) {
    return cloneDeep(priceAskWords.value)
      .filter((word) => word.clientType === PlatformEnum.PC)
      .map((word) => {
        word.clientType = PlatformEnum.Platform
        return word
      })
  } else {
    return priceAskWords.value
  }
}

async function handleOrderSubmit() {
  Modal.confirm({
    title: '提示',
    content: '是否确定提单？',
    async onOk() {
      const [err, res] = await fetchOrder({
        priceAskId: currentPriceSheet.value.id ?? 0,
        type: currentPriceSheet.value.type!,
        onLinePeriod: currentPriceSheet.value.onLinePeriod ?? '',
        comboName: currentPriceSheet.value.comboName ?? '',
        comboPriceName: currentPriceSheet.value.comboPriceName!,
        comboPriceId: currentPriceSheet.value.comboPriceId!,
        // 订单是百搜词包类型时，assessmentPrice字段传到comboPrice
        comboPrice: currentPriceSheet.value.comboPrice!,
        // 订单是百搜标王类型时，assessmentPrice字段传到assessmentPrice
        assessmentPrice: orderFields.value.assessmentPrice!,
        marketPrice: currentPriceSheet.value.marketPrice,
        sellerId: currentPriceSheet.value.sellerId ?? 0,
        sellerName: currentPriceSheet.value.sellerName ?? '',
        proxyId: currentPriceSheet.value.proxyId ?? 0,
        proxyName: currentPriceSheet.value.proxyName ?? '',
        orderWords: mergeOrderWordsIfPlatform() ?? [],
        customerName: selectedCustomer.value?.name ?? '',
        customerProxyId: selectedCustomer.value?.proxyId ?? 0,
        customerId: selectedCustomer.value?.id ?? 0,
        productId: currentPriceSheet.value.productId!,
        productName: currentPriceSheet.value.productName!,
        soldAreas: currentPriceSheet.value?.areas ?? '',
        versionType: currentPriceSheet.value?.versionType,
        industryCode: currentPriceSheet.value?.industryCode ?? 0,
        clientType: currentPriceSheet.value.clientType!,
        hasCreatePic: currentPriceSheet.value.hasCreatePic!,
        // 续费的查价单在提单时，要传入源订单的订单id
        oldOrderId: currentPriceSheet.value.oldOrderId
      })

      if (!err) {
        message.success(res.data.msg || '提单成功！')
        orderDisabled.value = true
        priceSheetStore.setCurrentPriceSheetStatus(StatusEnum.SUCCEED)
        orderDialog.show = false
        confirm.show = false
      }
    }
  })
}

async function handleChangeAudit() {
  formFields.value = defaultFormFields()
  // console.log(formFields.value.productId, '数值')

  dialog.show = true
  const [err] = await fetchIndustryList()

  if (!err) {
    // auditResult.value[0]?.industryCode
    // 如果审核结果已有，则需要回填上一次的审核行业
    // formFields.value.industryCode
    // 机审自带一个默认的行业
    const industryCode = auditResult.value[0]?.industryCode || formFields.value.industryCode
    const industryData = industryList.value.find((d) => d.code === industryCode)
    if (industryData) {
      formFields.value.industryId = industryData.id
      formFields.value.industryCode = industryData.code
    }
  }
}

function handleShowOrderDialog() {
  orderFields.value = defaultOrderFields()
  orderDialog.show = true
  handleOldOrderCustomer()
}

// 老订单续费产生的新订单，会自动回填老订单里的客户
async function handleOldOrderCustomer() {
  const { oldOrderId, type } = unref(currentPriceSheet)
  if (oldOrderId && type === TypeEnum.RENEWAL) {
    const [err, res] = await fetchOldOrderCustomer({
      oldOrderId: currentPriceSheet.value.oldOrderId
    })

    if (!err) {
      const [err1] = await handleCustomerSearch(res.data.data.name)
      if (!err1) {
        orderFields.value.customerId = res.data.data.id
      }
    }
  }
}

function handleBack() {
  router.go(-1)
}

function handleExportExcel(exportExcel: Function) {
  exportExcel(`关键词${Date.now()}`)
}

async function handlePreviewPrice() {
  previewDialog.show = true
  await fetchAssessmentPriceAskWord({
    assessmentPricesId: currentPriceSheet.value.assessmentPricesId || 0,
    originalAssessmentPrice: Number(currentPriceSheet.value.originalAssessmentPrice!),
    assessmentPrice: Number(currentPriceSheet.value.assessmentPrice!),
    id: currentPriceSheet.value.id
  })
}

function handleCoordinates() {
  const comboPriceName = currentPriceSheet.value.comboPriceName!
  const onLinePeriod = currentPriceSheet.value.onLinePeriod!
  const clientType = currentPriceSheet.value.clientType!
  //  生成xy坐标
  const coordinates = coordinatesHook.makeCoordinates(comboPriceName, onLinePeriod, clientType)

  coordinatesHook.setBaiduCoordinates(coordinates)
}
// 改变提单价格和市场价格
function handlePriceInput(e: any) {
  formFields.value.marketPrice = makeMarketPrice(e.target.value)
}
function handlePriceInputs(e: any) {
  formFields.value.comboPrice = makeMarketPrice(e.target.value)
}
onBeforeMount(() => {
  if (!currentPriceSheet.value.id) {
    router.replace('/price-manager')
  }
})

onMounted(() => {
  if (currentPriceSheet.value.id) {
    fetchAuditResult({
      priceAskId: currentPriceSheet.value.id
    })
    getRenewDetailFnitem()
    fetchPriceAskWords({
      priceAskId: currentPriceSheet.value.id
    })

    handleCoordinates()
  }
  if (currentPriceSheet.value.tpCode == 1 && currentPriceSheet.value.isCancel == 1) {
    tepizhuangstu.value = true
  }
})
</script>

<style lang="scss" scoped>
.main {
  &__extra {
    min-width: 242px;
    margin-left: 88px;
  }

  .statistic {
    width: 220px;
    text-align: right;
  }

  &__descriptions {
    margin-bottom: -8px;

    ::v-deep(.ant-descriptions-item-content) {
      overflow: hidden;
      flex-grow: 1;
    }
  }
}

.seacher {
  width: 220px;
}

.video-bg {
  background: blue;
}

.video-wrapper {
  mix-blend-mode: screen;
}
.biaotannsidx {
  font-size: 10px;
  text-align: right;
}
.tepititlecas {
  font-size: 15px;
  font-weight: 600;
}
.tepicontentca {
  font-size: 12px;
  margin-top: 10px;
  // color: #ccc;
}
</style>
